<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    let city = [
      { id: 1, parentId: 0, name: '江苏省' },
      { id: 2, parentId: 0, name: '广东省' },
      { id: 3, parentId: 0, name: '安徽省' },
      { id: 4, parentId: 1, name: '苏州市' },
      { id: 5, parentId: 1, name: '无锡市' },
      { id: 6, parentId: 2, name: '广州市' },
      { id: 7, parentId: 2, name: '深圳市' },
      { id: 8, parentId: 4, name: '吴中区' },
      { id: 9, parentId: 4, name: '姑苏区' },
      { id: 10, parentId: 4, name: '工业园区' }
    ]

    let arr = []
    city.forEach(item => {
      item.child = city.filter(r => r.parentId === item.id)
      if (item.parentId === 0) {
        arr.push(item)
      }
    })
    console.log(arr);
  </script>
</body>
</html>